package com.example.sicnuaccountingapp.data.repository

import com.example.sicnuaccountingapp.data.dao.TransactionDao
import com.example.sicnuaccountingapp.data.entity.Transaction
import kotlinx.coroutines.flow.Flow
import javax.inject.Inject

class TransactionRepository @Inject constructor(
    private val transactionDao: TransactionDao
) {
    suspend fun addTransaction(transaction: Transaction): Long {
        return transactionDao.insert(transaction)
    }

    suspend fun updateTransaction(transaction: Transaction) {
        transactionDao.updateTransaction(transaction)
    }

    suspend fun deleteTransaction(transaction: Transaction) {
        transactionDao.deleteTransaction(transaction)
    }

    suspend fun deleteTransactionById(userId: Long, transactionId: Long) {
        transactionDao.deleteTransactionById(userId, transactionId)
    }

    fun getAllTransactions(userId: Long): Flow<List<Transaction>> {
        return transactionDao.getAllTransactions(userId)
    }

    fun getTransactionsByDateRange(
        userId: Long,
        startDate: Long,
        endDate: Long
    ): Flow<List<Transaction>> {
        return transactionDao.getTransactionsByDateRange(userId, startDate, endDate)
    }
} 